﻿using Microsoft.Extensions.DependencyInjection;
using StockUI.Model;
using StockUI.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace StockUI.Views
{
    /// <summary>
    /// Home.xaml 的交互逻辑
    /// </summary>
    public partial class Home : UserControl
    {
        public Home()
        {
            InitializeComponent();
            this.DataContext = App.Current.Services.GetService<HomeViewModel>();
        }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //var homemodel = this.DataContext as HomeViewModel;

            //var data = ((TabControl)sender).SelectedItem as HomeTabsModel;

            //homemodel.ChangeItemCommand.Execute(data);
        }
        private void DataGrid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var dataGrid = (DataGrid)sender;

            // 获取可见列的数量
            int visibleColumnsCount = dataGrid.Columns.Count(column => column.Visibility == Visibility.Visible);

            // 计算平均列宽
            double averageColumnWidth = dataGrid.ActualWidth / visibleColumnsCount;

            // 设置所有可见列的宽度
            foreach (var column in dataGrid.Columns.Where(column => column.Visibility == Visibility.Visible))
            {
                column.Width = new DataGridLength(averageColumnWidth);
            }
        }
    }
}
